package com.lovo.middleman.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.middleman.bean.SellCarBean;
import com.lovo.middleman.bean.StockBean;
import com.lovo.middleman.mapper.SellCarMapper;
import com.lovo.middleman.mapper.StockMapper;
import com.lovo.middleman.service.ISellCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SellCarServiceImpl extends ServiceImpl<SellCarMapper, SellCarBean> implements ISellCarService {

    @Autowired
    SellCarMapper sellCarMapper;

    @Autowired
    StockMapper stockMapper;

    @Override
    public List<SellCarBean> querySellCarBean(int userId) {
        QueryWrapper<SellCarBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return  sellCarMapper.selectList(queryWrapper);
    }

    @Override
    public void addSellCarBean(int stockId) {
        //根据id 查出的库存商品 , 再将其所需要的属性添加至购物车?
        StockBean stockBean = stockMapper.selectById(stockId);
        SellCarBean sellCarBean = new SellCarBean();
        sellCarBean.setGoodsName(stockBean.getGoodsName());
        sellCarBean.setBrand(stockBean.getBrand());
        sellCarBean.setSellPrice(stockBean.getMarketingPrice());
        sellCarMapper.insert(sellCarBean);
    }

    @Override
    public void deleteSellCarBean(int id) {
        sellCarMapper.deleteById(id);
    }
}
